﻿Imports System.Data.OleDb
Imports BUS
Imports DTO
Public Class frmhosohocsinh
#Region "Load DSHS"
    Public Sub LoadDS()
        Dim bus As New HocSinhBUS()
        Dim dt As New DataTable()
        dt = bus.LayBangHS()
        dgvdanhsachhs.DataSource = dt
    End Sub
#End Region
#Region "FormLoad"
    Private Sub frmhosohocsinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim bus As New HocSinhBUS()
        Dim ds As List(Of String)
        ds = bus.DSGioiTinh()
        Dim n, i As Integer
        n = ds.Count()
        For i = 0 To n - 1
            cmbgioitinh.Items.Add(ds(i))
        Next
        cmbgioitinh.SelectedIndex = 0
        'load danh sach hoc sinh len
        LoadDS()
    End Sub
#End Region
    

    


    Private Sub btndong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndong.Click
        Me.Close()
    End Sub

    Private Sub btnThem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim hsDTO As New HocSinhDTO
        hsDTO.Ma = txtMSSV.Text
        hsDTO.Ten = txthoten.Text
        hsDTO.NS = dtpkngaysinh.Value.Date
        hsDTO.GT = cmbgioitinh.Text
        hsDTO.Email = txtemail.Text
        hsDTO.DC = txtdiachi.Text
        Dim bus As New HocSinhBUS()
        Dim kq As Integer
        kq = bus.ThemHS(hsDTO)
        If (kq = 1) Then
            MessageBox.Show("Thêm thành công")
        Else
            MessageBox.Show("Thêm thất bại")
        End If
        LoadDS()
    End Sub

    Private Sub dgvdanhsachhs_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvdanhsachhs.SelectionChanged
        Dim rowselected As Integer
        rowselected = Convert.ToInt32(dgvdanhsachhs.CurrentRow.Index)
        txtMSSV.Text = dgvdanhsachhs.Rows(rowselected).Cells(0).Value
        txthoten.Text = dgvdanhsachhs.Rows(rowselected).Cells(1).Value
        'cmbgioitinh .Text = 
    End Sub
End Class
